GBML manual / Lists

list_length

How many items target currently holds - 0 for an empty list, up to target's own declared capacity once it is full.

Syntax

list_length(target) -> int

Arguments

NameType
targetlist

Returns

int

Description

How many items target currently holds - 0 for an empty list, up to target's own declared capacity (/// @capacity, or 8 if untagged) once it is full.

This is how many items are IN target right now, not its capacity - a common use is checking whether there is still room before deciding what to do next (list_length(target) < 4), or showing a count on the HUD.

Example

/// @type {list<int>}
var scores = [10, 20, 30];
var count = list_length(scores); // 3
A real capture - an empty list, list_length reading 0A real capture - an empty list, list_length reading 0
A real capture - an empty list, list_length reading 0
The same list after filling it with the example's three scores - list_length now 3The same list after filling it with the example's three scores - list_length now 3
The same list after filling it with the example's three scores - list_length now 3

The empty list on the left is not part of the example above (which starts already filled) - shown first here so the picture also teaches list_length(target) tracking target as it fills, not just the single number the documented example itself returns.

On the GBA

Just the vector's size() - O(1), never walks the list. This is how many items are IN target right now, not target's capacity (the number `/// @capacity` declared, or 8 if untagged) - a full list has list_length(target) == its own capacity, an empty one has list_length(target) == 0.

See also: list_addlist_removelist_clearlist_filllist_copylist_containsarray_lengthData containerslist_sortlist_foreachlist_filter